package serveur;

import Communication.Couple;

public class Math {
	
	public static int min(int a, int b) {
	    return (a <= b) ? a : b;
	}
	
	public static int max(int a, int b) {
	    return (a <= b) ? b : a;
	}
	
	public static int ensureRange(int value, int min, int max) {
		   return min(max(value, min), max);
	}

	public static boolean inRange(int value, int min, int max) {
		   return (value>= min) && (value<= max);
	}
	
	public static Couple ensureBox(Couple p, Couple p1, Couple p2){
		return new Couple(ensureRange(p.x, p1.x, p2.x), ensureRange(p.y, p1.y, p2.y));
	}
	
	public static boolean inBox(Couple p, Couple p1, Couple p2){
		return inRange(p.x, p1.x, p2.x) && inRange(p.y, p1.y, p2.y);
	}
	
	public static boolean inBox(Couple p, Box box){
		return inBox(p,box.p1,box.p2);
	}
	
	public static int f2Int(float f){
		return java.lang.Math.round(f);
	}
}
